#!/bin/bash
cmd=/usr/local/inotify/bin
Src=/backup
Dst=backup
user=rsync_backup
rsync_passfile=/etc/rsyncd.passwd
Host=10.100.100.105
if [ ! -e "$Src" ]||[ ! -e "${rsync_passfile}" ]||[ ! -e "$cmd" ]||[ ! -e "/usr/bin/rsync" ];then
	echo "Check file and folder"
	exit 1
fi
$cmd/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e create,close_write,delete $Src |while read line
do
	if [ -f $line ];then
		rsync -az --delete $line  --timeout=100 $user@$Host::$Dst --password-file=${rsync_passfile} 
	else
	   cd $Src && rsync -aruz -R  --delete ./ --timeout=100  $user@$Host::$Dst --password-file=${rsync_passfile} &>/dev/null 2>&1
	fi
done
exit 0
